<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function arr(people, limit) {
      people.sort((a, b) => (a - b));
      let ans = 0,
        left = 0,//左指针初始化在0的位置
        right = people.length - 1 //右指针初始化在people.length - 1的位置
      while (left <= right) {//两指针向中间靠拢 遍历
        if ((people[left] + people[right--]) <= limit) {
          left++
        }
        ans++
      }
      return ans
    };
    console.log(arr([1, 2], 3));
  </script>
</body>

</html>